class Solution {
    public int wiggleMaxLength(int[] nums) {
        int n=nums.length;
        int ret=0;
        if(n<2) return n;
        int pre=0;

        int i=0;


        while(i<n-1){
            int right=nums[i+1]-nums[i];
            if(right==0){
                i++;
                continue;
            }
            if(pre*right<=0) ret++;
            pre=right;
            i++;

        }
        return ret+1;
    }
}
           
           